﻿using Microsoft.EntityFrameworkCore;
using Product.Domain;
using Product.Domain.Entity;
using Product.Infrastructure.DBContexts;

namespace Product.Infrastructure;

public class ProductTypeRepository : IProductTypeRepository
{
    private readonly ProductDbContext _dbContext;


    public ProductTypeRepository(ProductDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public async Task<List<ProductType>> FindAllProductTypeAsync()
    {
        return await _dbContext.ProductTypes.ToListAsync();
    }

    public async Task<List<ProductType>> GetProductTypeByProductIdAsync(Guid ProductId)
    {
        List<ProductType> productType = new List<ProductType>();
        var result = await _dbContext.ProductVariants.Where(x => x.Deleted == false && x.Visible == true && x.ProductId == ProductId).ToListAsync();
        foreach (var item in result)
        {
            var type = await _dbContext.ProductTypes.SingleOrDefaultAsync(x => x.Id == item.ProductTypeId);
            productType.Add(type);
        }
        return productType;
    }

    public Task<string> GetTypeNameByProductTypeId(Guid productTypeId)
    {
        throw new NotImplementedException();
    }
}
